from django import template
from openpolitics.utils import party_affiliation as raw_pa

register = template.Library()

@register.simple_tag
def party_affiliation(pid, type=None):
    try:
        if type=='name':
            return (raw_pa(pid=pid)).name
        elif type=='shortname':
            return (raw_pa(pid=pid)).name
        else:
            return raw_pa(pid=pid)
    except:
        return ""

